<?php
	require_once('../utils/logged_in.php');
	require_once('../utils/query.php');
	
	$range = $_POST['range'];
	$name_filter = $_POST['name_filter'];
	$sort_by = $_POST['sort_by'];
?>

<!--<ul class="items">-->
<ul>
	<?php
		$filter = '';
		$columns = '';
		
		if ($name_filter)
			$filter = $filter . " AND name LIKE '%" . mysql_real_escape_string($name_filter) . "%'";
		if ($sort_by)
			$filter = $filter . " ORDER BY " . mysql_real_escape_string($sort_by);
		if ($range)
			$filter = $filter . " LIMIT " . mysql_real_escape_string($range);
		
		$cards_result = execute_query_unsafe("SELECT storeitemid, name, description, price, image" . $columns . " FROM StoreItem " . $join . " WHERE TRUE" . $filter);
		while ($row = mysql_fetch_array($cards_result))
		{
			$storeid = $row[0];
			$name = $row[1];
			$description = $row[2];
			$price = $row[3];
			$image = $row[4];
			
			if(strlen($name) > 16)
				$showname = substr ($name,0,16) . "...";
			else
				$showname = $name;
				
			$point_text = "Untold Points";
			if ($price == 1)
				$point_text = "Untold Point";
	?>
			
			<li class="item" id="<?php echo($storeid); ?>">
				<div class="itemImg">
					<img src="../../../card_imgs/<?php echo($image); ?>">
				</div>
				<div class="itemName" title="<?php echo($name); ?>">
					<?php echo($showname); ?>
				</div>
				<div class="itemDesc">
					<?php echo($description); ?>
				</div>
				<div class="itemPrice">
					<?php echo($price . " " . $point_text); ?>
				</div>
				<div class="numPrice" style="display:none;">
				<?php echo($price); ?>
				</div>
				<div class="fullName" style="display:none;">
				<?php echo($name); ?>
				</div>
			</li>
	<?php
		}
	?>
</ul>
